package com.exam.examtest.util

import android.app.ProgressDialog
import android.content.Context
import android.view.Window
import androidx.appcompat.app.AppCompatActivity
import com.lzy.okgo.callback.StringCallback
import com.lzy.okgo.request.base.Request

/**
 * ClassName StringDialogCallback
 * Create by rhf
 * Create on 2021/3/30 17:56
 * Description 请求对话框回调
 */
@Suppress("DEPRECATION")
abstract class StringDialogCallback (activity: Context?)  : StringCallback(){

    private var dialog: ProgressDialog? = null

    init {
        dialog = ProgressDialog(activity)
        dialog?.requestWindowFeature(Window.FEATURE_NO_TITLE)
        dialog?.setCanceledOnTouchOutside(false)
        dialog?.setProgressStyle(ProgressDialog.STYLE_SPINNER)
        dialog?.setMessage("请求网络中...")
    }

    override fun onStart(request: Request<String, out Request<*, *>>?) {
        if (dialog != null && !dialog!!.isShowing) {
            dialog!!.show()
        }
    }


    override fun onFinish() {
        if (dialog != null && dialog!!.isShowing) {
            dialog!!.dismiss()
        }
    }
}